  

import { Ref, watch } from 'vue'
import { useCustomCellBuilder } from './dag-hooks'
import type { Graph } from '@antv/x6'
import { WorkflowDefinition } from './types'

interface Options {
  graph: Ref<Graph | undefined>
  definition: Ref<WorkflowDefinition | undefined>
}

/**
 * Backfill workflow into graph
 */
export function useGraphBackfill(options: Options) {
  const { graph, definition } = options

  const { buildGraph } = useCustomCellBuilder()

  watch([graph, definition], () => {
    if (graph.value && definition.value) {
      graph.value.fromJSON(buildGraph(definition.value))
    }
  })

  return {}
}
